// composables/api/user.ts
import { useApi } from '../../useApi'

// 定义接口返回数据类型（TypeScript 可选，增强类型提示）
export type UserInfo = {
    id: number
    name: string
    email: string
}

export type LoginParams = {
    username: string
    password: string
}

export type LoginResult = {
    token: string
    user: UserInfo
}

// 用户相关 API 方法
export const userApi = {
    // 获取用户信息
    getUserInfo: (userId: number) => {
        return useApi<UserInfo>(`/users/${userId}`)
    },

    // 登录
    login: (params: LoginParams) => {
        return useApi<LoginResult>('/auth/login', {
            method: 'POST',
            body: params
        })
    },

    // 退出登录
    logout: () => {
        return useApi<{ success: boolean }>('/auth/logout', {
            method: 'POST'
        })
    }
}